﻿<?session_start();
if(!defined('sugarEntry'))define('sugarEntry', true);
/*********************************************************************************
module : vng sales marketing
author : hoanghd@vinagame.com.vn
********************************************************************************/
require_once('XTemplate/xtpl.php');
require_once('log4php/LoggerManager.php');
require_once('include/modules.php');
require_once('modules/ZT2Remit/ZT2Remit.php');

global $current_language;
global $app_strings;
global $app_list_strings;
global $theme;
$theme_path = 'themes/' . $theme . '/';
$image_path = $theme_path .'images/';
require_once($theme_path . 'layout_utils.php');
global $mod_strings;
global $current_user;


$_type =_get('tp');
$_id =$_POST['id'];

$_timePlayingtt = $_POST['playingtime'];
$_pcstt = $_POST['pcs'];

//$_rand =$_POST['rnd']!=''?$_POST['rnd']:$_GET['rnd'];
$fnc = new FNC();


$seed = new ZT2Remit_Ext();

// kiem tra quyen access 
if ($seed->ACLAccess('view')) {
    
   
	ob_start();
	if ($_type=='epmtt_dl')
	{
			$seed->email_template_import();	
			die();
	}	
	else if ($_type=='get_ef_config_add_form'){	

       
    
	$list_form = new XTemplate('modules/ZT2Remit/Detail.html');	
           
    $msg='';
    
		if ($_id !='')
        {
                
                
        $gridview='';
        $DBList = $seed->setList($fnc,$_id,$_vl_from_date,$_vl_to_date,$locationId,$_pst_statusId,$list_form);   
        //$DBList = $seed->setList($fnc,$_where,$_vl_from_date,$list_form);	
    	$gridview.= $seed->_AddPageHeader();
    	//$gridview.= $seed->PageHeader();
    	$exportGrid = $seed->setHeader();
    	$exportGrid.= $DBList[0];
    	$gridview.= $exportGrid;		
    	$gridview.=$seed->setFooter();
    	$gridview.=$seed->setPaging();
        
    
        $list_form->assign('_timeplaying',$_timePlayingtt);
        $list_form->assign('_pcs',$_pcstt);   
        $list_form->assign('name_timeplaying',' Tổng số Playing time: ');
        $list_form->assign('name_pcs','Tổng số PCs: '); 
        $list_form->assign('phut','(phút) ');         
        $list_form->assign('title','Chi tiết phòng máy theo PCs');         
    
		$list_form->assign('gridview',$gridview);
		$list_form->parse('main');
		$info = $list_form->out_return('main');	
		}else{
			$info = 'Bạn không có quyền truy cập vào trang này !';
		}
          
    
		die($info);		
		//$info = $out->out_return('main');
		
		//echo $out;
		die();	
	}
	else{
		sugar_die('You do not have access to this area. Contact your site administrator to obtain access.');	
	}
	




	
	ob_end_flush();
} else {
	ACLController::displayNoAccess();
	sugar_die('');
}

class ZT2Remit_Ext  extends ZT2Remit
{
    
    function _AddPageHeader(){
		$_PageHeader=' <br>';
		/*if ($this->ACL_Access('Create','ePMTT')){		
			$_PageHeader=' <br><input type=button value="Thêm m?i b?n bè" onclick="user_add()"> <br> <br>'; 
		}*/
		return 	$_PageHeader;	
	}
    


	function setHeader(){		

			if ($_POST['mode']=='EXPORT' || !$this->ACL_Page(2,'List')){
			$ArrHeader = array('STT'						
	       //	,'STT'
            ,'Ngày'
			,'Tài khoản phòng máy'	
            ,'Máy trạm'
            ,'Thời gian(phút)'
            
			);
		}
		else{
			$ArrHeader = array(//'<input type=checkbox id=check_all name=check_all>'						
		  'STT'
            ,'Ngày'
			,'Tài khoản phòng máy'	
            ,'Máy trạm'
            ,'Thời gian(phút)'
            
			);
			
		}
		$SortHeader = array(0,0,0,0,0,0,0,0);
		//$SortImage[$_POST['_SortOrderBy']]='css_right ui-icon ui-icon-carat-2-n-s';
		if ($_POST['_OrderDirection']=='desc'){
			$SortImage[$_POST['_SortOrderBy']]='css_right ui-icon ui-icon-triangle-1-s';
		}else if ($_POST['_OrderDirection']=='asc'){
			$SortImage[$_POST['_SortOrderBy']]='css_right ui-icon ui-icon-triangle-1-n';
		}
		
		
		$_Header='';
		$_Header.='<div class="hastable"><div id="aj_result"><table   width="100%"  cellspacing="0"  cellpadding="0" border=0>';
		$_Header.='<thead><tr>';
		
		for ($j=0;$j<count($ArrHeader);$j++)
		{
		
			if ($SortHeader[$j])
			{
				if ($SortImage[$j]==''){$SortImage[$j]='css_right ui-icon ui-icon-carat-2-n-s';}
				
				$_Header.='<th class="ui-state-default t_cap" valign=top>
				<a href=javascript:fnOrder('.$j.') >'.$ArrHeader[$j].'
					<span class="'.$SortImage[$j].'"></span>
				</a></th>';
			}
			else
				$_Header.='<th class="ui-state-default t_cap">'.$ArrHeader[$j].'</th>';
		}
		$_Header.='</tr></thead>';
		return $_Header;
	}
    
    function setList($fnc,$_id,$_vl_from_date,$_vl_to_date,$locationId,$_pst_statusId,$list_form){	
		$result = NULL;	
		$PageSize=10;		
		$this->PageIndex = isset($_POST["page"]) ? $_POST["page"] : 1;		
		if ($_POST['ddlPageSize']!=''){$PageSize=$_POST['ddlPageSize'];}
		$this->PageSize = $PageSize;
		$_FlgExport=false;
		if($_POST['mode']=='EXPORT'){$PageSize=0;$_FlgExport=true;}

		$_Table = '';
		if ($_FlgExport)
		{	$_Field = array('configName','gamecode','from_date','to_date');	
		}else{
			$_Field = array('configName','gamecode','from_date','to_date');	
		}
		
		$_strField = implode(',', $_Field);
		if ($filter!='')	
		{
			$filter_arr = explode('|',$filter);
		}
			
	
		// ===== order =============/
		$_SortOrderBy=$_POST["_SortOrderBy"];
		$_OrderDirection=$_POST["_OrderDirection"];
		
		if (trim($_SortOrderBy)=='' || $_FlgExport)
		{
			$_OrderBy = 'CSMID';
			$_OrderDirection = 'asc';	
		}
		else
		{
			$_OrderBy = $_Field[$_SortOrderBy-1];			
		}
		// ===== order =============/


		try
		{	

	
			$_dblist='';			
			$i=0;
			
          	if ($_POST['mode_inpvl']=='EXPORT')			
			
                $sSQL="set ANSI_NULLS ON;set ANSI_WARNINGS ON;exec usp_ZT2_Remit_be_PlayingTime_Detail_List  '".$_id."'";
				
            else
            
			 $sSQL="set ANSI_NULLS ON;set ANSI_WARNINGS ON;exec usp_ZT2_Remit_be_PlayingTime_Detail_List  '".$_id."'";
				
         // echo $sSQL;
            
			$this->ws_debug($sSQL);
				
				$result = $this->db->query($sSQL, true, "Query failed");				
			
				while ($aR = $this->db->fetchByAssoc($result))
				{
					
					if ($i==0){
				
					}					
				
					$STT = ($i+($this->PageIndex-1)*$PageSize)+1;                   
                    
                    $_recordate = $aR['RecordDate'];                    
                   	$_acountPM = $aR['newZingId']; 				
                    $_pcName = $aR['PCName'];                   
                    $temp =  $fnc->isNull($aR['PlayingTime'],0);                                                
                    $_playingTime = number_format(ceil($temp / 60),0,'','.');
                      
                    //end m                    	
					
					$_dblist.='<tr>';
							
					if ($_POST['mode']=='EXPORT' || !$this->ACL_Page(2,'List')){
						$_dblist.='<td  style="text-align:center" width=50>'.$STT.'</td>';							
					}else{

						$arr_attr_keyword = array('style'=>'');
				      }                            
					$_dblist.='<td  style="text-align:left">'.$STT.'</td>';
                    $_dblist.='<td  style="text-align:left">'.$fnc->date2vndate($_recordate,false).'</td>';
                    $_dblist.='<td  style="text-align:left">'.$_acountPM.'</td>';
                    $_dblist.='<td  style="text-align:left">'.$_pcName.'</td>';
                    $_dblist.='<td  style="text-align:left">'.$_playingTime.'</td>'; 
                       
																												
					$_dblist.='</tr>';			
				
					
					$i++;
				}				
			
			
			if ($i==0){
					if ($this->TotalRecord==0)
						{
							$_dblist.='<tr><td colspan=100>Không tìm thấy thông tin</td></tr>';	
						}	
			}else{	}
			
				
		}
		catch (PDOException $ex)
		{}			
		
		$list[0] = $_dblist;

			
		return $list;			
		
	}
    
    
    
    
}

?>